var SaleReprot = (function(){
    var getLid = function(){
        return $("#jqSelect").val();
    };
    var getStartTime = function(){
        if($('input:radio[name="dateTrigger"]:checked'))
            return $('input:radio[name="dateTrigger"]:checked').val();
    };
    var getType = function(){
        return $("#cType").val();
    };

    function _focusGraphic(res) {
        domCode.className = 'col-md-4 ani';
        domGraphic.className = 'col-md-8 ani';
        if (needRefresh) {
            myChart.showLoading();
            setTimeout(_refresh(false,res), 1000);
        }
    }

    function _refresh(isBtnRefresh,res){
        if (isBtnRefresh) {
            needRefresh = true;
            _focusGraphic(res);
            return;
        }
        needRefresh = false;
        if (myChart && myChart.dispose) {
            myChart.dispose();
        }
        myChart = echarts.init(domMain, curTheme);
        window.onresize = myChart.resize;
        (new Function(editor.doc.getValue()))();
//        console.log(option);
//        return;
        for(var i in res.city){
            option.series[0].data[i] = {
                name:res.city[i].city,
                value: res.city[i].torder};
        }
       var k = parseInt(i);
        for(var j in res.province){
           var l = parseInt(j);
            option.series[0].data[k+l] = {
                name:res.province[j].province,
                value: res.province[j].torder};
        }
//        console.log(option);
        console.log(option.series[0]);
        myChart.setOption(option, true);
        domMessage.innerHTML = '';
    }
    function init(){
        $(".dateTrigger,#jqSelect").on("change",function(){
            var lid = getLid();
            var startTime = getStartTime();
            var cType = getType();
            if(!lid){
                console && console.log("缺省lid");
                return false;
            }
            if(!startTime){
                console && console.log("缺省startTime");
                return false;
            }
            if(!cType){
                console && console.log("缺省cType");
                return false;
            }
            PFT_GLOBAL.G.Ajax({
                url : "http://www.12301.cc/module/zax/baiduline/get_ticket.php",
                data : { lid:lid, btime3:startTime,type:cType},
                dataType : "json",
                type :'GET',
                loading : function(){
                    myChart.showLoading();
                },
                removeLoading : function(data){
                    myChart.hideLoading();
                },
                timeout : function(){console && console.log("获取数据超时")},
                serverError : function(){console &&
                console.log("接口出错www.12301.cc/module/zax/baiduline/get_ticket.php")}
            },function(res){
                _refresh(true,res);
            });

        })
    }

    init()
})();
